-- 18.lua
-- Created by zouyb Jun/26/2015
-- 光元素BUFF光效

return {
    onAppear = function(monster)
		-- 当前关卡
		local uiCurLevel = UIDungeonMgr.getCurLevel();

	    -- 当前怪物的基类ID
		local baseClassId = monster:query("base_class_id");

        local needAddBuf = false;

		-- 获取其他所有光元素
        local openMonsterGrids = UIDungeonMgr:getCurLevel():getOpenMonsterGrids();
        local count = 0;
        for i = 1, #openMonsterGrids do
            local monsterGrid = openMonsterGrids[i];
            local tempBaseId = monsterGrid.gridData.monster:query("base_class_id");
            if tempBaseId == 18 then
                -- 统计光元素数目
                count = count + 1;
            elseif tempBaseId == 19 then
                -- 是否有暗元素在场
                needAddBuf = true;
            end
        end

        if needAddBuf then
            -- 暗元素在场，播放“属性增益”光效
            local monsterGrid = UIDungeonMgr:getCurLevel().grids[monster:getPos()];
            playAddBuffEffect(monsterGrid, BUFF_TYPE_ATTACK);
        end

        if count == 1 then
            for i = 1, #openMonsterGrids do
    			local monsterGrid = openMonsterGrids[i];
				-- 首次出现光元素，其他暗元素播放“属性增益”光效
    			if monsterGrid.gridData.monster:query("base_class_id") == 19 then
    				playAddBuffEffect(monsterGrid, BUFF_TYPE_ATTACK);
    			end
    		end
    	end
    end,

    onDie = function(monster)
		-- 当前关卡
		local uiCurLevel = UIDungeonMgr.getCurLevel()

	    -- 当前怪物的基类ID
		local baseClassId = monster:query("base_class_id");

		-- 获取其他所有光元素
        local openMonsterGrids = UIDungeonMgr:getCurLevel():getOpenMonsterGrids();
        local count = 0;
        for i = 1, #openMonsterGrids do
            local monsterGrid = openMonsterGrids[i];
            if monsterGrid.gridData.monster:query("base_class_id") == 18 then
                count = count + 1;
            end
        end

        if count == 0 then
			-- 最后一个光元素死亡，其他暗元素播放“属性减益”光效
            for i = 1, #openMonsterGrids do
    			local monsterGrid = openMonsterGrids[i];
    			if monsterGrid.gridData.monster:query("base_class_id") == 19 then
    				playAddDeBuffEffect(monsterGrid, DEBUFF_TYPE_ATTACK);
    			end
    		end
    	end
    end,
};